package com.uidp.domain;

import static com.uidp.bundle.Messages.GROUP_NAME_NOT_FOUND;

import java.util.List;

import com.acsior.dac.exeption.DataAccessException;
import com.acsior.sbc.exception.BusinessException;
import com.acsior.sbc.exception.SearchException;
import com.acsior.sbc.exception.ValidationException;
import com.acsior.sbc.impl.hibernate.HibernateBusinessObject;
import com.uidp.hibernatelayer.UsergroupsDAO;
import com.uidp.hibernatelayer.UsergroupsVO;
import com.uidp.search.UsergroupSearch;

public class Usergroups extends
		HibernateBusinessObject<UsergroupsVO, UsergroupsDAO> {

	private String groupname;
	private String description;

	/**
	 * @param username
	 *            - потребителско име
	 * @return IUser - резултат
	 * 
	 * @throws BusinessException
	 * @throws SearchException
	 */
	public static List<Usergroups> searchActiveByUserName(String username)
			throws BusinessException, SearchException {
		UsergroupSearch search = new UsergroupSearch(username);
		search.execute();

		if (search.getResult().isEmpty()) {
			throw new BusinessException(GROUP_NAME_NOT_FOUND, username);
		}

		return search.getResult();
	}

	public Usergroups() throws BusinessException {
		super();
	}

	/**
	 * @param e
	 * @throws BusinessException
	 */
	public Usergroups(UsergroupsVO h) throws BusinessException {
		super(h);

	}

	/** @see PersistentObject#initialize() */
	@Override
	protected void initialize() throws BusinessException {
		super.initialize();
	}

	@Override
	protected void setValues(UsergroupsVO h) throws DataAccessException {
		h.setGroupname(getGroupname());
		h.setDescription(getDescription());
	}

	@Override
	protected void copyProperties(UsergroupsVO d, boolean deepCopy)
			throws BusinessException {
		setGroupname(d.getGroupname());
		setDescription(d.getDescription());

	}

	@Override
	protected void validate() throws ValidationException {
		// TODO Auto-generated method stub

	}

	@Override
	protected Class<UsergroupsDAO> getDAOClass() {
		return UsergroupsDAO.class;
	}

	public String getGroupname() {
		return groupname;
	}

	public void setGroupname(String groupname) {
		this.groupname = groupname;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}
